package com.zjcode.cdcer.config;

import java.util.HashMap;
import java.util.Map;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * mq配置
 */
@Configuration
public class RabbitMQConfig {


    public static final String EXCHANGE_NAME = "fileimp_exchange";

    public static final String QUEUE = "fileimp_queue";


    /**
     * topic 交换机
     *
     * @return
     */
    @Bean
    public Exchange fileImpExchange() {
        return ExchangeBuilder
            .topicExchange(EXCHANGE_NAME)
            .durable(true)
            .build();
    }


    /**
     * 队列
     *
     * @return
     */
    @Bean
    public Queue fileImpQueue() {
        return QueueBuilder
            .durable(QUEUE)
            .build();
    }


    /**
     * 交换机和队列绑定关系
     */
    @Bean
    public Binding fileImpBinding(Queue queue, Exchange exchange) {
        return BindingBuilder
            .bind(queue)
            .to(exchange)
            .with("fileimp.#")
            .noargs();
    }

}
